
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>基于日期的混入 &#8212; Django 3.2.6.dev 文档</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="基于类的通用视图——扁平化索引" href="flattened-index.html" />
    <link rel="prev" title="编辑混入" href="mixins-editing.html" />



 
<script src="../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 3.2.6.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="mixins-editing.html" title="编辑混入">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="flattened-index.html" title="基于类的通用视图——扁平化索引">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-class-based-views-mixins-date-based">
            
  <div class="section" id="s-date-based-mixins">
<span id="date-based-mixins"></span><h1>基于日期的混入<a class="headerlink" href="#date-based-mixins" title="永久链接至标题">¶</a></h1>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">这些混入中的所有日期格式化属性都使用 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式字符，请不要尝试使用 <a class="reference internal" href="../templates/builtins.html#std:templatetag-now"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">now</span></code></a> 模板标签的格式字符，因为它们不兼容。</p>
</div>
<div class="section" id="s-yearmixin">
<span id="yearmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">YearMixin</span></code><a class="headerlink" href="#yearmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.YearMixin">
<em class="property">class </em><code class="descname">YearMixin</code><a class="headerlink" href="#django.views.generic.dates.YearMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个可用于检索和提供日期的年份成分解析信息的混入。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.YearMixin.year_format">
<code class="descname">year_format</code><a class="headerlink" href="#django.views.generic.dates.YearMixin.year_format" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式，解析年份时使用。默认情况下，是 <code class="docutils literal notranslate"><span class="pre">'%Y'</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.YearMixin.year">
<code class="descname">year</code><a class="headerlink" href="#django.views.generic.dates.YearMixin.year" title="永久链接至目标">¶</a></dt>
<dd><p><strong>可选的</strong> 年数值，为字符串。默认情况下，设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，这意味着年份将通过其他方式确定。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.YearMixin.get_year_format">
<code class="descname">get_year_format</code>()<a class="headerlink" href="#django.views.generic.dates.YearMixin.get_year_format" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 在解析年份时使用的格式。默认返回 <a class="reference internal" href="#django.views.generic.dates.YearMixin.year_format" title="django.views.generic.dates.YearMixin.year_format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">year_format</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.YearMixin.get_year">
<code class="descname">get_year</code>()<a class="headerlink" href="#django.views.generic.dates.YearMixin.get_year" title="永久链接至目标">¶</a></dt>
<dd><p>返回此视图将显示数据的年份，为一个字符串。按顺序尝试以下来源：</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.dates.YearMixin.year" title="django.views.generic.dates.YearMixin.year"><code class="xref py py-attr docutils literal notranslate"><span class="pre">YearMixin.year</span></code></a> 属性的值。</li>
<li>URL 模式中捕获的 <code class="docutils literal notranslate"><span class="pre">year</span></code> 参数值。</li>
<li><code class="docutils literal notranslate"><span class="pre">GET</span></code> 查询  <code class="docutils literal notranslate"><span class="pre">year</span></code> 参数的值。</li>
</ul>
<p>如果找不到有效的年份规格，则引发 404。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.YearMixin.get_next_year">
<code class="descname">get_next_year</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.YearMixin.get_next_year" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含提供的日期后的第一年的第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.YearMixin.get_previous_year">
<code class="descname">get_previous_year</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.YearMixin.get_previous_year" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含所提供日期前一年的第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-monthmixin">
<span id="monthmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">MonthMixin</span></code><a class="headerlink" href="#monthmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.MonthMixin">
<em class="property">class </em><code class="descname">MonthMixin</code><a class="headerlink" href="#django.views.generic.dates.MonthMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个可用于检索并提供日期中月份成分的解析信息的混入。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.MonthMixin.month_format">
<code class="descname">month_format</code><a class="headerlink" href="#django.views.generic.dates.MonthMixin.month_format" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式在解析月份时使用。默认情况下，是 <code class="docutils literal notranslate"><span class="pre">'%b'</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.MonthMixin.month">
<code class="descname">month</code><a class="headerlink" href="#django.views.generic.dates.MonthMixin.month" title="永久链接至目标">¶</a></dt>
<dd><p><strong>可选的</strong> 月份数值，为字符串。默认情况下，设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，这意味着月份将通过其他方式确定。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.MonthMixin.get_month_format">
<code class="descname">get_month_format</code>()<a class="headerlink" href="#django.views.generic.dates.MonthMixin.get_month_format" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 在解析月份时使用的格式。默认返回 <a class="reference internal" href="#django.views.generic.dates.MonthMixin.month_format" title="django.views.generic.dates.MonthMixin.month_format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">month_format</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.MonthMixin.get_month">
<code class="descname">get_month</code>()<a class="headerlink" href="#django.views.generic.dates.MonthMixin.get_month" title="永久链接至目标">¶</a></dt>
<dd><p>以字符串形式返回此视图将显示数据的月份。 按顺序尝试以下来源：</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.dates.MonthMixin.month" title="django.views.generic.dates.MonthMixin.month"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MonthMixin.month</span></code></a> 属性的值。</li>
<li>URL 模式中捕获的 <code class="docutils literal notranslate"><span class="pre">month</span></code> 参数值。</li>
<li><code class="docutils literal notranslate"><span class="pre">GET</span></code> 查询  <code class="docutils literal notranslate"><span class="pre">month</span></code> 参数的值。</li>
</ul>
<p>如果找不到有效的月份规格，则引发 404。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.MonthMixin.get_next_month">
<code class="descname">get_next_month</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.MonthMixin.get_next_month" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含提供的日期后的第一个月的第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.MonthMixin.get_previous_month">
<code class="descname">get_previous_month</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.MonthMixin.get_previous_month" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含所提供日期前一个月的第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-daymixin">
<span id="daymixin"></span><h2><code class="docutils literal notranslate"><span class="pre">DayMixin</span></code><a class="headerlink" href="#daymixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.DayMixin">
<em class="property">class </em><code class="descname">DayMixin</code><a class="headerlink" href="#django.views.generic.dates.DayMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个可用于检索并提供日期中的日期成分的解析信息的混入。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.DayMixin.day_format">
<code class="descname">day_format</code><a class="headerlink" href="#django.views.generic.dates.DayMixin.day_format" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式，在解析日期时使用。默认情况下，是 <code class="docutils literal notranslate"><span class="pre">'%d'</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.DayMixin.day">
<code class="descname">day</code><a class="headerlink" href="#django.views.generic.dates.DayMixin.day" title="永久链接至目标">¶</a></dt>
<dd><p><strong>可选的</strong> 日期的数值，为字符串。默认情况下，设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，这意味着将使用其他方式确定日期。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DayMixin.get_day_format">
<code class="descname">get_day_format</code>()<a class="headerlink" href="#django.views.generic.dates.DayMixin.get_day_format" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式，用于解析当天的情况。默认返回 <a class="reference internal" href="#django.views.generic.dates.DayMixin.day_format" title="django.views.generic.dates.DayMixin.day_format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">day_format</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DayMixin.get_day">
<code class="descname">get_day</code>()<a class="headerlink" href="#django.views.generic.dates.DayMixin.get_day" title="永久链接至目标">¶</a></dt>
<dd><p>返回此视图将显示数据的日期，为一个字符串。按顺序尝试以下来源：</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.dates.DayMixin.day" title="django.views.generic.dates.DayMixin.day"><code class="xref py py-attr docutils literal notranslate"><span class="pre">DayMixin.day</span></code></a> 属性的值。</li>
<li>URL 模式中捕获的 <code class="docutils literal notranslate"><span class="pre">day</span></code> 参数值。</li>
<li><code class="docutils literal notranslate"><span class="pre">GET</span></code> 查询  <code class="docutils literal notranslate"><span class="pre">day</span></code> 参数的值。</li>
</ul>
<p>如果找不到有效的日期规格，则引发 404。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DayMixin.get_next_day">
<code class="descname">get_next_day</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.DayMixin.get_next_day" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含提供的日期后的下一个有效日期。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DayMixin.get_previous_day">
<code class="descname">get_previous_day</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.DayMixin.get_previous_day" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个包含前一天有效日期的日期对象。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-weekmixin">
<span id="weekmixin"></span><h2><code class="docutils literal notranslate"><span class="pre">WeekMixin</span></code><a class="headerlink" href="#weekmixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.WeekMixin">
<em class="property">class </em><code class="descname">WeekMixin</code><a class="headerlink" href="#django.views.generic.dates.WeekMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个可用于检索和提供日期的周成分的解析信息的混入。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.WeekMixin.week_format">
<code class="descname">week_format</code><a class="headerlink" href="#django.views.generic.dates.WeekMixin.week_format" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 格式，解析一周时使用。默认情况下，它是 <code class="docutils literal notranslate"><span class="pre">'%U'</span></code>，这意味着一周从周日开始。如果你的星期从周一开始，则设置为 <code class="docutils literal notranslate"><span class="pre">'%W'``或</span> <span class="pre">``'%V'</span></code> （ISO 8601 星期）。</p>
<div class="versionadded">
<span class="title">New in Django 3.2:</span> <p>增加了对 <code class="docutils literal notranslate"><span class="pre">'%V'</span></code> 周格式的支持。</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.WeekMixin.week">
<code class="descname">week</code><a class="headerlink" href="#django.views.generic.dates.WeekMixin.week" title="永久链接至目标">¶</a></dt>
<dd><p><strong>可选的</strong> 周数值，为字符串。默认情况下，设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，这意味着将使用其他方式确定星期。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.WeekMixin.get_week_format">
<code class="descname">get_week_format</code>()<a class="headerlink" href="#django.views.generic.dates.WeekMixin.get_week_format" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference external" href="https://docs.python.org/3/library/time.html#time.strftime" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> 在解析星期时要使用的格式。默认返回 <a class="reference internal" href="#django.views.generic.dates.WeekMixin.week_format" title="django.views.generic.dates.WeekMixin.week_format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">week_format</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.WeekMixin.get_week">
<code class="descname">get_week</code>()<a class="headerlink" href="#django.views.generic.dates.WeekMixin.get_week" title="永久链接至目标">¶</a></dt>
<dd><p>返回此视图将显示数据的星期，为字符串。按顺序尝试以下来源：</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.dates.WeekMixin.week" title="django.views.generic.dates.WeekMixin.week"><code class="xref py py-attr docutils literal notranslate"><span class="pre">WeekMixin.week</span></code></a> 属性的值。</li>
<li>URL 模式中捕获的 <code class="docutils literal notranslate"><span class="pre">week</span></code> 参数值。</li>
<li><code class="docutils literal notranslate"><span class="pre">GET</span></code> 查询 <code class="docutils literal notranslate"><span class="pre">week</span></code> 参数的值。</li>
</ul>
<p>如果找不到有效的周数规格，则引发 404。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.WeekMixin.get_next_week">
<code class="descname">get_next_week</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.WeekMixin.get_next_week" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含提供的日期后的一周第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.WeekMixin.get_prev_week">
<code class="descname">get_prev_week</code>(<em>date</em>)<a class="headerlink" href="#django.views.generic.dates.WeekMixin.get_prev_week" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个日期对象，包含提供的日期前一周的第一天。根据 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="django.views.generic.dates.BaseDateListView.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_empty</span></code></a> 和 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a> 的值，该函数也可以返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 或引发 <a class="reference internal" href="../../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 异常。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-datemixin">
<span id="datemixin"></span><h2><code class="docutils literal notranslate"><span class="pre">DateMixin</span></code><a class="headerlink" href="#datemixin" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.DateMixin">
<em class="property">class </em><code class="descname">DateMixin</code><a class="headerlink" href="#django.views.generic.dates.DateMixin" title="永久链接至目标">¶</a></dt>
<dd><p>一个混入类，为所有基于日期的视图提供通用行为。</p>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.DateMixin.date_field">
<code class="descname">date_field</code><a class="headerlink" href="#django.views.generic.dates.DateMixin.date_field" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">QuerySet</span></code> 模型中 <code class="docutils literal notranslate"><span class="pre">DateField</span></code> 或 <code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code> 的名称，基于日期的档案应使用该名称来确定页面上显示的对象列表。</p>
<p>当 <a class="reference internal" href="../../topics/i18n/timezones.html"><span class="doc">时区支持</span></a> 被启用，并且 <code class="docutils literal notranslate"><span class="pre">date_field</span></code> 是 <code class="docutils literal notranslate"><span class="pre">DateTimeField</span></code> 时，日期被认为是在当前时区。否则，查询集可以包括最终用户时区的前一天或第二天的对象。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">在这种情况下，如果你已经实现了每个用户的时区选择，那么根据最终用户的时区，同一个 URL 可能会显示一组不同的对象。为了避免这种情况，你应该使用一个 <code class="docutils literal notranslate"><span class="pre">DateField</span></code> 作为 <code class="docutils literal notranslate"><span class="pre">date_field</span></code> 属性。</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.DateMixin.allow_future">
<code class="descname">allow_future</code><a class="headerlink" href="#django.views.generic.dates.DateMixin.allow_future" title="永久链接至目标">¶</a></dt>
<dd><p>一个布尔值，用于指定是否将“未来”对象列入本页，其中“未来”是指 <code class="docutils literal notranslate"><span class="pre">date_field</span></code> 中指定的字段大于当前日期／时间的对象。默认情况下，这是 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DateMixin.get_date_field">
<code class="descname">get_date_field</code>()<a class="headerlink" href="#django.views.generic.dates.DateMixin.get_date_field" title="永久链接至目标">¶</a></dt>
<dd><p>返回包含日期数据的字段名，该字段将在此视图上操作。默认返回 <a class="reference internal" href="#django.views.generic.dates.DateMixin.date_field" title="django.views.generic.dates.DateMixin.date_field"><code class="xref py py-attr docutils literal notranslate"><span class="pre">date_field</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.DateMixin.get_allow_future">
<code class="descname">get_allow_future</code>()<a class="headerlink" href="#django.views.generic.dates.DateMixin.get_allow_future" title="永久链接至目标">¶</a></dt>
<dd><p>确定是否将“未来”对象包含在本页中，“未来”是指在 <code class="docutils literal notranslate"><span class="pre">date_field</span></code> 中指定的字段大于当前日期/时间的对象。默认返回 <a class="reference internal" href="#django.views.generic.dates.DateMixin.allow_future" title="django.views.generic.dates.DateMixin.allow_future"><code class="xref py py-attr docutils literal notranslate"><span class="pre">allow_future</span></code></a>。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-basedatelistview">
<span id="basedatelistview"></span><h2><code class="docutils literal notranslate"><span class="pre">BaseDateListView</span></code><a class="headerlink" href="#basedatelistview" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.dates.BaseDateListView">
<em class="property">class </em><code class="descname">BaseDateListView</code><a class="headerlink" href="#django.views.generic.dates.BaseDateListView" title="永久链接至目标">¶</a></dt>
<dd><p>一个为所有基于日期的视图提供通用行为的基类。通常没有理由实例化 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView" title="django.views.generic.dates.BaseDateListView"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseDateListView</span></code></a>; 实例化一个子类来代替。</p>
<p>当这个视图（及其子类）执行时，<code class="docutils literal notranslate"><span class="pre">self.object_list</span></code> 将包含该视图正在操作的对象列表，<code class="docutils literal notranslate"><span class="pre">self.date_list</span></code> 将包含可用数据的日期列表。</p>
<p><strong>混入</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.dates.DateMixin" title="django.views.generic.dates.DateMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateMixin</span></code></a></li>
<li><a class="reference internal" href="mixins-multiple-object.html#django.views.generic.list.MultipleObjectMixin" title="django.views.generic.list.MultipleObjectMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultipleObjectMixin</span></code></a></li>
</ul>
<p><a href="#id1"><span class="problematic" id="id2">**</span></a>方法和属性*</p>
<dl class="attribute">
<dt id="django.views.generic.dates.BaseDateListView.allow_empty">
<code class="descname">allow_empty</code><a class="headerlink" href="#django.views.generic.dates.BaseDateListView.allow_empty" title="永久链接至目标">¶</a></dt>
<dd><p>一个布尔值，用于指定是否在没有对象的情况下显示页面。如果这个值为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，并且没有可用的对象，视图将显示一个空页面，而不是引发 404。</p>
<p>这和 <a class="reference internal" href="mixins-multiple-object.html#django.views.generic.list.MultipleObjectMixin.allow_empty" title="django.views.generic.list.MultipleObjectMixin.allow_empty"><code class="xref py py-attr docutils literal notranslate"><span class="pre">django.views.generic.list.MultipleObjectMixin.allow_empty</span></code></a> 是一样的，只是默认值是 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.dates.BaseDateListView.date_list_period">
<code class="descname">date_list_period</code><a class="headerlink" href="#django.views.generic.dates.BaseDateListView.date_list_period" title="永久链接至目标">¶</a></dt>
<dd><p><strong>可选的</strong> 定义 <code class="docutils literal notranslate"><span class="pre">date_list</span></code> 的聚合周期的字符串。它必须是 <code class="docutils literal notranslate"><span class="pre">'year'</span></code> （默认）、<code class="docutils literal notranslate"><span class="pre">'month'</span></code> 或 <code class="docutils literal notranslate"><span class="pre">'day'</span></code> 之一。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.BaseDateListView.get_dated_items">
<code class="descname">get_dated_items</code>()<a class="headerlink" href="#django.views.generic.dates.BaseDateListView.get_dated_items" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个包含 (<code class="docutils literal notranslate"><span class="pre">date_list</span></code>, <code class="docutils literal notranslate"><span class="pre">object_list</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_context</span></code>) 的三元元组。</p>
<p><code class="docutils literal notranslate"><span class="pre">date_list</span></code> 是可用数据的日期列表。<code class="docutils literal notranslate"><span class="pre">object_list</span></code> 是对象的列表。<code class="docutils literal notranslate"><span class="pre">extra_context</span></code> 是上下文数据的字典，它将被添加到由 <a class="reference internal" href="mixins-multiple-object.html#django.views.generic.list.MultipleObjectMixin" title="django.views.generic.list.MultipleObjectMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultipleObjectMixin</span></code></a> 提供的任何上下文数据中。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.BaseDateListView.get_dated_queryset">
<code class="descname">get_dated_queryset</code>(<em>**lookup</em>)<a class="headerlink" href="#django.views.generic.dates.BaseDateListView.get_dated_queryset" title="永久链接至目标">¶</a></dt>
<dd><p>返回使用 <code class="docutils literal notranslate"><span class="pre">lookup</span></code> 定义的查询参数过滤的查询集。强制执行对查询集的任何限制，如 <code class="docutils literal notranslate"><span class="pre">allow_empty</span></code> 和 <code class="docutils literal notranslate"><span class="pre">allow_future</span></code>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.BaseDateListView.get_date_list_period">
<code class="descname">get_date_list_period</code>()<a class="headerlink" href="#django.views.generic.dates.BaseDateListView.get_date_list_period" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <code class="docutils literal notranslate"><span class="pre">date_list</span></code> 的聚合周期。默认返回 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.date_list_period" title="django.views.generic.dates.BaseDateListView.date_list_period"><code class="xref py py-attr docutils literal notranslate"><span class="pre">date_list_period</span></code></a>。</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.dates.BaseDateListView.get_date_list">
<code class="descname">get_date_list</code>(<em>queryset</em>, <em>date_type=None</em>, <em>ordering='ASC'</em>)<a class="headerlink" href="#django.views.generic.dates.BaseDateListView.get_date_list" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <code class="docutils literal notranslate"><span class="pre">date_type</span></code> 类型的日期列表，其中 <code class="docutils literal notranslate"><span class="pre">queryset</span></code> 包含条目。例如，<code class="docutils literal notranslate"><span class="pre">get_date_list(qs,</span> <span class="pre">'year')</span></code> 将返回 <code class="docutils literal notranslate"><span class="pre">qs</span></code> 有条目的年份列表。如果没有提供 <code class="docutils literal notranslate"><span class="pre">date_type</span></code>，则使用 <a class="reference internal" href="#django.views.generic.dates.BaseDateListView.get_date_list_period" title="django.views.generic.dates.BaseDateListView.get_date_list_period"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_date_list_period()</span></code></a> 的结果。<code class="docutils literal notranslate"><span class="pre">date_type</span></code> 和 <code class="docutils literal notranslate"><span class="pre">ordering</span></code> 被传递给 <a class="reference internal" href="../models/querysets.html#django.db.models.query.QuerySet.dates" title="django.db.models.query.QuerySet.dates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.dates()</span></code></a>。</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">基于日期的混入</a><ul>
<li><a class="reference internal" href="#yearmixin"><code class="docutils literal notranslate"><span class="pre">YearMixin</span></code></a></li>
<li><a class="reference internal" href="#monthmixin"><code class="docutils literal notranslate"><span class="pre">MonthMixin</span></code></a></li>
<li><a class="reference internal" href="#daymixin"><code class="docutils literal notranslate"><span class="pre">DayMixin</span></code></a></li>
<li><a class="reference internal" href="#weekmixin"><code class="docutils literal notranslate"><span class="pre">WeekMixin</span></code></a></li>
<li><a class="reference internal" href="#datemixin"><code class="docutils literal notranslate"><span class="pre">DateMixin</span></code></a></li>
<li><a class="reference internal" href="#basedatelistview"><code class="docutils literal notranslate"><span class="pre">BaseDateListView</span></code></a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="mixins-editing.html"
                        title="上一章">编辑混入</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="flattened-index.html"
                        title="下一章">基于类的通用视图——扁平化索引</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/class-based-views/mixins-date-based.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">7月 23, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="mixins-editing.html" title="编辑混入">previous</a>
     |
    <a href="../index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="flattened-index.html" title="基于类的通用视图——扁平化索引">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>